<?php

require_once(dirname(__FILE__) . '/appconf.php');

class Block extends Site {

    function setup() {
        $this->run_modes('show', 'b1', 'b2', 'b3', 'b3_1', 'b4', 'b5','b5_1', 'b6', 'b7', 'b8', 'b9', 'b10', 'b11', 'b12', 'b13', 'b14', 'b15', 'clear', 'fb', 'b16', 'b16_1', 'b17', 'b18','b19');
        $this->start_mode('b1');
        $this->selfurl = '/block.php';
        $this->pagesize = 3;
        parent::setup();
    }

    function cgiapp_prerun($rm='') {
        $this->Product = getModel('Model_Product');
        $this->Event = getModel('Model_Event');
        $this->Member = getModel('Model_Member');
        $this->Lookup = getModel('Model_Lookup');
        $this->ProductReports = getModel('Model_ProductReports');
        $this->IMoreNews = getModel('Model_IMoreNews');
        $this->ProductReportsComment = getModel('Model_ProductReportsComment');
        $this->IndexHelp = getModel('Model_IndexHelp');
        $this->EventNew = getModel('Model_EventNew');
        $this->Top5 = getModel('Model_Top5');
        parent::cgiapp_prerun();
    }

    //index 文字
    function action_b1() {
        $_return = <<<RETURN
                    <style>body{margin:0;padding:0;}</style>
                    <script type='text/javascript'><!--//<![CDATA[
                    var m3_u = (location.protocol=='https:'?'https://ads.nmg.com.hk/www/delivery/ajs.php':'http://ads.nmg.com.hk/www/delivery/ajs.php');
                    var m3_r = Math.floor(Math.random()*99999999999);
                    if (!document.MAX_used) document.MAX_used = ',';
                    document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
                    document.write ("?zoneid=433");
                    document.write ('&amp;cb=' + m3_r);
                    if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
                    document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
                    document.write ("&amp;loc=" + escape(window.location));
                    if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
                    if (document.context) document.write ("&context=" + escape(document.context));
                    if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
                    document.write ("'><\/scr"+"ipt>");
                    //]]>--></script><noscript><a href='http://ads.nmg.com.hk/www/delivery/ck.php?n=a7c4ac5e&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://ads.nmg.com.hk/www/delivery/avw.php?zoneid=433&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a7c4ac5e' border='0' alt='' /></a></noscript>
RETURN;
        echo $_return;
    }

    //ad
    function action_b2() {
        $_return = <<<RETURN
                    <style>body{margin:0;padding:0;}</style>
                    <script type='text/javascript'><!--//<![CDATA[
                    var m3_u = (location.protocol=='https:'?'https://ads.nmg.com.hk/www/delivery/ajs.php':'http://ads.nmg.com.hk/www/delivery/ajs.php');
                    var m3_r = Math.floor(Math.random()*99999999999);
                    if (!document.MAX_used) document.MAX_used = ',';
                    document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
                    document.write ("?zoneid=431");
                    document.write ('&amp;cb=' + m3_r);
                    if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
                    document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
                    document.write ("&amp;loc=" + escape(window.location));
                    if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
                    if (document.context) document.write ("&context=" + escape(document.context));
                    if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
                    document.write ("'><\/scr"+"ipt>");
                    //]]>--></script><noscript><a href='http://ads.nmg.com.hk/www/delivery/ck.php?n=a7644aa4&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://ads.nmg.com.hk/www/delivery/avw.php?zoneid=431&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a7644aa4' border='0' alt='' /></a></noscript>
RETURN;
        echo $_return;
    }

    //search
    function action_b3() {
        $search_hot_arr = db_query_hash('sb_search_hotpicks', array('field' => 'cname', 'where' => 'live=1 and status=1', 'order' => 'sequence asc'));
        $_hot_arr = array();
        if (!empty($search_hot_arr['result'])) {
            foreach ($search_hot_arr['result'] as $key => $value) {
                if (!empty($value['cname']))
                    $_hot_arr[] = $value['cname'];
            }
        }
        //$_hot_arr = array('尊尚', '芳香', '護手霜');
        $_return = '<div class="hd"><h2 class="hd_title">搜尋</h2></div>
                    <div class="bd">
                    <input type="hidden" name="action" value="product" />
                    <input type="text" id="find" onkeyup="lookup(this.value,1);" name="find"  class="search_ipt" value="keyword" id="search" onfocus="find_onfocus(this);" onblur="find_onblur(this);"/>
                    <a class="btn_search" href="javascript:void(0);" onclick="window.location.href=\'/search-product/\'+$(\'#find\').val()">
                    <span>搜尋</span></a>
                    <div id="autoSuggestionsList" style="width:177px;margin-top:-9px;"></div>
                    <p><span class="search_hot">熱門搜尋：</span>';
        foreach ($_hot_arr as $k => $v) {
            $_return .= "<a href='/search-product/" . $v . "'>" . $v . "</a> ";
        }
        $_return .= "</p></div>";
        echo $_return;
    }

    //search ajax
    function action_b3_1() {
        $kvcobj = getCache('block_b3_1', array('expire' => 3600 * 7));
        $find = $this->get_q('find', '');
        $find = htmlentities($find, ENT_QUOTES | ENT_IGNORE, "UTF-8");
        $type = $this->get_q('t', 1, 'int'); //類型，1產品，2活動，3會員
        $data = $kvcobj->get('t' . $type . '_' . $find);
        if (!$data) {
            $param = array();
            $param['order'] = "id asc";
            $param['limit'] = 10;

            if ($type == 1) {
                $param['field'] = "name as search";
                $param['where'] = "name like '" . $find . "%'";
                $data1 = db_query_hash('brand', $param);
                $param['field'] = "name as search";
                $param['where'] = "name like '" . $find . "%'";
                $data2 = db_query_hash('product', $param);
                $param['field'] = "cname as search";
                $param['where'] = "cname like '" . $find . "%'";
                $data3 = db_query_hash('product', $param);

                $data['result'] = array_merge($data1['result'], $data2['result'], $data3['result']);
            } elseif ($type == 2) {
                $param['field'] = "title as search";
                $param['where'] = "title like '" . $find . "%'";
                $data1 = db_query_hash('event', $param);
                $param['field'] = "brand_str as search";
                $param['where'] = "brand_str like '" . $find . "%'";
                $data2 = db_query_hash('event', $param);

                $data['result'] = array_merge($data1['result'], $data2['result']);
            } elseif ($type == 3) {
                $param['field'] = "username as search";
                $param['where'] = "username like '" . $find . "%'";
                $data = db_query_hash('member_imore', $param);
            }
            $kvcobj->set('t' . $type . '_' . $find, $data);
        }
        if (!empty($data['result'])) {
            $li = '';
            foreach ($data['result'] as $k => $v) {
                if ($k > 9)
                    break;
                $search = $v['search'];
                $li .= '<li class="find_li" onClick="fill(\'' . $search . '\',' . $type . ');" >' . $search . '</li>';
            }
            echo $li;
        }
    }

    //體驗活動、工作坊
    function action_b4() {
        //$data = $this->Event->getEventList(0,1,"TB1.id desc",1,1);
        $kvcobj = getCache('block_b4', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->EventNew->getList();
            $event_css = ($data['event_type'] == 1) ? "hd_title" : "hd_title_1";
            if (!empty($data)) {
                $_return = '<div class="hd"><h2 class="hd_title ' . $event_css . '">體驗工作坊/體驗活動</h2></div>
                            <div class="bd"><div class="show_box">
							<div class="img_box"><p class="img_p"><a href="' . $data['url'] . '"><span><img src="' . PhotoResize($data['photo'], 295, 157) . '"></span></a></p></div>
							</div><div class="text_box"><p class="name">' . $data['title'] . '</p></div>
                            <a class="btn_s btn_s_join fr" href="' . $data['url'] . '"><strong>立即申請</strong></a>
                            </div>';
            } else {
                $_return = '';
            }
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //人氣排行榜
    function action_b5() {
        $kvcobj = getCache('block_b5', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            //$data = $this->Product->getProductList(0, 3, "TB1.click desc,TB1.id desc", 1, 5, '', 0);
            $li_redate = $this->Top5->getList();
            //sos(var_export($li_redate));
            $_return = '<div class="hd"><h2 class="hd_title">產品排行榜</h2></div><div class="bd"><ul class="rank_list">';
            $ii = 1;
            foreach ($li_redate as $k => $v) {
                $_return .= '<li><span class="rank rank' . $ii . '">' . $ii . '</span>
                            <i class="crown"></i>
							<div class="img_box"><p class="img_p"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '"><span><img src="' . PhotoResize($v['cover'], 100, 100) . '"></span></a></p></div>
                            <h4 class="title"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '" class="title">' . wordscut($v['type_name'], 9) . '</a></h4>
                            <h4 class="title"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '">' . wordscut($v['cname'], 9) . '</a></h4>
                            <p class="rank_report">';
                $_return .= $v['member_type'] == 5 ? '體驗團報告 / <span href="#">' . db_query_count('product_reports', "oid=" . mysql_escape_string($v['id']) . " and status=1 and is_accept=1") . '個</span><br/><br/></p></li>' : '用戶心得 / <span href="#">' . db_query_count('product_reports', "oid=" . mysql_escape_string($v['id']) . " and status=1 and is_accept=1") . '個</span><br/><br/></p></li>';
                $ii++;
				if($ii>3) break;
            }
            $_return .= '</ul></div>';
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }
	
	//人氣排行榜
    function action_b5_1() {
        $kvcobj = getCache('block_b5_1', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            //$data = $this->Product->getProductList(0, 3, "TB1.click desc,TB1.id desc", 1, 5, '', 0);
            $li_redate = $this->Top5->getList();
            //sos(var_export($li_redate));
            $_return = '<div class="hd"><h2 class="hd_title">產品排行榜</h2></div><div class="bd"><ul class="rank_list">';
            $ii = 1;
            foreach ($li_redate as $k => $v) {
                $_return .= '<li><span class="rank rank' . $ii . '">' . $ii . '</span>
                            <i class="crown"></i>
							<div class="img_box"><p class="img_p"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '"><span><img src="' . PhotoResize($v['cover'], 100, 100) . '"></span></a></p></div>
                            <h4 class="title"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '" class="title">' . wordscut($v['type_name'], 9) . '</a></h4>
                            <h4 class="title"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '">' . wordscut($v['cname'], 9) . '</a></h4>
                            <p class="rank_report">';
                $_return .= $v['member_type'] == 5 ? '體驗團報告 / <span href="#">' . db_query_count('product_reports', "oid=" . mysql_escape_string($v['id']) . " and status=1 and is_accept=1") . '個</span><br/><br/></p></li>' : '用戶心得 / <span href="#">' . db_query_count('product_reports', "oid=" . mysql_escape_string($v['id']) . " and status=1 and is_accept=1") . '個</span><br/><br/></p></li>';
                $ii++;
            }
            $_return .= '</ul></div>';
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //fackbook
    function action_b6() {
        echo '<div class="fb-activity" data-site="imore.hk" data-app-id="' . FB_APPID . '" data-width="300" data-height="300" data-header="true" data-recommendations="false"></div>';
    }

    //特選報告
    function action_b7() {
        $kvcobj = getCache('block_b7', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->ProductReports->getReportsList(0, 0, 0, "TB1.sequence desc", 1, 3, 1, "", 0, 1);
            $_return = '<div class="hd">
                        <h2 class="hd_title">特選體驗報告</h2>
                        </div>
                        <div class="bd">
                        <ul class="report_f_list">';
            foreach ($data['result'] as $k => $v) {
                $data1 = $this->Product->getProductById($v['oid']);
                $_return .= '<li>
							<div class="img_box"><p class="img_p"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type']) . '"><span><img src="' . PhotoResize($data1['cover'], 116, 116) . '"></span></a></p></div>
                            <div class="details">
                            <h4 class="product_brand"><a class="product_brand" href="' . optimize_url('product', 'detail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type']) . '">' . $data1['type_name'] . '</a></h4>
                            <p class="product_title">
                            <a href="' . optimize_url('product', 'detail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type']) . '">' . wordscut($data1['name'], 12) . '
                            <br>
                            ' . wordscut($data1['cname'], 12) . '</a>
                            </p>
                            <div class="product_info">
                            <div class="img_box_s">
							<p class="img_p"><a href="' . optimize_url('person', 'report', 'username=' . $v['username']) . '" target=_blank> 
							<span><img width=58 src="' . imore_avatar($v['photo']) . '" alt="" >
							</span></a></p>
                            </div>
                            <p class="product_intro">
                            <a href="' . optimize_url('product', 'reportDetail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type'] . '&rid=' . $v['id']) . '">
                            ' . wordscut($v['body'], 50) . '
                            </a>
                            </p>
                            <a class="more" href="' . optimize_url('product', 'reportDetail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type'] . '&rid=' . $v['id']) . '">更多</a>
                            </div>
                            </div>
                            </li>';
            }
            $_return .= '	</ul></div>';
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //imore 最新資訊
    function action_b8() {
        $kvcobj = getCache('block_b8', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->IMoreNews->getIMoreNews("id desc", 1, 8);
            $_return = '<div class="imore_news_box b_box"><div class="hd"><h2 class="hd_title">iMORE NEWS</h2></div><ul class="i_news_list">';
            foreach ($data['result'] as $k => $v) {
                $_return .= '<li><a href="http://www.imore.hk/shownews.php?id=' . $v['id'] . '">' . wordscut($v['topic'], 20) . '</a></li>';
            }
            $_return .= '</ul></div>';
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //試用申請三步驟
    function action_b9() {
        $kvcobj = getCache('block_b9', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->IndexHelp->getIndexHelp();
            $_return = '<div class="hd">
                    <h2 class="hd_title">
                    新手教學
                    </h2>
                    </div>
                    <div class="bd">
					<div class="img_box"><p class="img_p"><a  href="' . $data[0]['url'] . '"><span><img src="' . PhotoResize($data[0]['photo_image1'], 130, 130) . '"></span></a></p></div>
                    <p class="descript">' . wordscut($data[0]['body'], 44) . '</p>
                    <a class="btn_s btn_s_video btn_s_video_a" href="' . $data[0]['url'] . '"><strong>觀看教學</strong></a>
                    <div class="info">
                    <h3 class="question">
                    ' . $data[1]['title'] . '
                    </h3>
                    <p class="answer">' . wordscut($data[1]['body'], 130) . '</p>
                    <a class="btn_s btn_s_video fr" href="' . $data[1]['url'] . '"><strong>觀看教學</strong></a>
                    </div>
                    </div>';
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //使用攻略
    function action_b10() {
        $_return = "<div style='width:300px;margin-top:10px;height:250px;display:block;border:1px solid #000;'>";
        $_return .= "<div>試用攻略</div>";
        $_return .= "<div>1、XXX X X XX XXX X XX XXX XXX XX XX XXX XX XX XXX XX XX XXX X XX XX</div>";
        $_return .= "<div>2、XXX X X XX XXX X XX XXX XXX XX XX XXX XX XX XXX XX XX XX X XX X</div>";
        $_return .= "<div>3、XXX X X XX XXX X XX XXX XXX XX XX XXX XX XX XXX XX XX XX  XX XX</div>";
        $_return .= "</div>";
        echo $_return;
    }

    //最新試用邀請
    function action_b11() {
        $kvcobj = getCache('block_b11', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->Product->getProductList(1, 3, "TB1.apply_starttime desc,TB1.id desc", 1, 3, '', 0);
            $_return = '<div class="hd">
                    <h2 class="hd_title">
                    最新試用邀請
                    </h2>
                    </div>
                    <div class="bd">
                    <ul class="rank_list">';
            foreach ($data['result'] as $k => $v) {
				$name = $v['cname']?$v['cname']:$v['name'];
                $_return .= '	<li>
						<div class="img_box"><p class="img_p"><a href="' . optimize_url('product', 'invite_inpage', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '"><span><img src="' . PhotoResize($v['cover'], 70, 70) . '"></span></a></p></div>
                        <h4 class="title"><a href="' . optimize_url('product', 'invite_inpage', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '">' . $v['type_name'] . '</a></h4>
                        <p class="product_title"><a href="' . optimize_url('product', 'invite_inpage', 'pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '">' . wordscut($name, 20) . '</a></p>
                        <p class="quota">人氣 <span>' . $v['click'] . '</span></p>
                        </li>';
            }
            $_return .= '</ul></div>';
            $kvcobj->set('return', $_return);
        }

        echo $_return;
    }

    //其他報告
    function action_b12() {
        $kvcobj = getCache('block_b12', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->ProductReports->getReportsList(0, 0, 0, "TB1.id desc", 1, 3, 1);
            //echo '<pre>'.var_export($data,1).'</pre>';
            $_return = "<div style='width:300px;margin-top:10px;height:250px;display:block;border:1px solid #000;'>";
            $_return .= "<div>其他報告</div>";
            foreach ($data['result'] as $k => $v) {
                $data1 = $this->Product->getProductById($v['oid']);
                $_return .= "<div style='float:left;width:25%;'><a href='" . optimize_url('person', 'report', 'username=' . $v['username']) . "' target='_parent'><img src='" . PhotoResize($v['photo'], 50, 50) . "'/><br/>" . $v['username'] . "</a></div>";
                $_return .= "<div style='float:left;width:74%;'><a href='" . optimize_url('product', 'reportDetail', 'mtype=' . $data1['member_type'] . '&pid=' . $v['oid'] . '&rid=' . $v['id']) . "'  target='_parent'>" . wordscut($v['body'], 30) . "</a></div>";
                $_return .= "<hr style='clear:both;' />";
            }
            $_return .= "</div>";
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //成為會員
    function action_b13() {
        $_return = '<div class="hd">
                    <h2 class="hd_title">
                    成為會員
                    </h2>
                    </div>
                    <div class="bd">
                    <p>成為 iMORE 會員，即可申請成為試用專員及體驗達人，將有機會試用港台最新最紅的美妝護膚、頭髮及個人護理產品！
                    </p>
                    <a class="btn_s btn_s_apply fr" href="/member.php?action=reg"><strong>立即申請</strong></a>
                    </div>';
        echo $_return;
    }

    //評論試用報告
    function action_b14() {
        $kvcobj = getCache('block_b14', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->ProductReports->getReportsList(0, 0, 0, "TB1.sequence desc", 1, 3, 1, "", 1);
            $_return = '<div class="hd">
                    <h2 class="hd_title">評論試用報告</h2>
                    </div>
                    <div class="bd">
                    <ul class="report_c_list  v_list">';
            foreach ($data['result'] as $k => $v) {
                $data1 = $this->Product->getProductById($v['oid']);
                if (!empty($data1)) {
                    $_return .= $k == 0 ? '<li class="first">' : '<li>';
                    $_return .= '
							<div class="img_box"><p class="img_p"><a href="' . optimize_url('product', 'detail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type']) . '"><span><img src="' . PhotoResize($data1['cover'], 116, 116) . '"></span></a></p></div>
                            <div class="details">
                            <h4 class="product_brand"><a class="product_brand" href="' . optimize_url('product', 'detail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type']) . '">' . $data1['type_name'] . '</a></h4>
                            <p class="product_title">
                            <a href="' . optimize_url('product', 'detail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type']) . '">' . wordscut($data1['name'], 12) . '
                            <br>' . wordscut($data1['cname'], 12) . '</a></p>
                            <div class="product_info">
                            <div class="img_box_s">
							<p class="img_p"><a href="' . optimize_url('person', 'report', 'username=' . $v['username']) . '" target=_blank> 
							<span><img width=58 src="' . imore_avatar($v['photo']) . '" alt="" >
							</span></a></p>
                            </div>
                            <p class="product_intro"><a href="' . optimize_url('product', 'reportDetail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type'] . '&rid=' . $v['id']) . '">' . wordscut($v['body'], 40) . '</a></p>
                            <a class="more" href="' . optimize_url('product', 'reportDetail', 'pid=' . $v['oid'] . '&mtype=' . $data1['member_type'] . '&rid=' . $v['id']) . '">更多</a>
                            </div>
                            </div>
                            </li>';
                }
            }
            $_return .= '</ul></div>';
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //最新體驗邀請
    function action_b15() {
        $kvcobj = getCache('block_b15', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->Product->getProductList(5, 3, "TB1.apply_starttime desc,TB1.id desc", 1, 3, '', 0);
            $_return = '<div class="hd">
                    <h2 class="hd_title">
                    最新體驗邀請
                    </h2>
                    </div>
                    <div class="bd">
                    <ul class="rank_list">';
            foreach ($data['result'] as $k => $v) {
				$name = $v['cname']?$v['cname']:$v['name'];
                $_return .= '	<li>
						<div class="img_box"><p class="img_p"><a href="product.php?action=invite_inpage&pid=' . $v['id'] . '&mtype=' . $v['member_type'] . '"><span><img src="' . PhotoResize($v['cover'], 70, 70) . '"></span></a></p></div>
                        <h4 class="title"><a class="product_brand" href="' . optimize_url('product', 'invite_inpage', '&pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '">' . $v['type_name'] . '</a></h4>
                        <p class="product_title"><a href="' . optimize_url('product', 'invite_inpage', '&pid=' . $v['id'] . '&mtype=' . $v['member_type']) . '">' . wordscut($name, 20) . '</a></p>
                        <p class="quota">人氣 <span>' . $v['click'] . '</span></p>
                        </li>';
            }
            $_return .= '</ul></div>';

            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    function action_clear() {
        $kvc = trim($this->get_q('kvc', ''));
        clear_kvcache($kvc);
    }

    //產品報告分享
    function action_fb() {
        $u = $this->get_q('u', '');
        $_return = '<a name="fb_share" type="button" share_url="' . $u . '" > </a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>';
        echo $_return;
    }

    //個人頁面報告
    function action_b16() {
        $uid = intval($this->get_q('uid', '0', 'int'));
        $kvcobj = getCache('block_b16', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return_' . $uid);
        if (!$_return) {
            $data = $this->ProductReports->getReportsList(0, $uid, 0, "TB1.addtime desc", 1, 5, 1);
			if(!empty($data['result'])){
				$_return = '<div class="hd">
				<h2><span class="username">' . $data['result'][0]['username'] . '</span> <span class="hd_title">的最新報告</span></h2>
				</div>
							<div class="bd" id="sidebar_person_newreport"><ul class="newreport_list">';
				foreach ($data['result'] as $k => $v) {
					$data1 = $this->Product->getProductById($v['oid']);
					$_return .= '<li><i class="square"></i>
								<a href="' . optimize_url('product', 'reportDetail', '&pid=' . $v['oid'] . '&mtype=' . $data1['member_type'] . '&rid=' . $v['id']) . '">' . wordscut($v['title'], 20) . '</a></li>';
				}
				$_return .= '</ul>';
				if (intval($data['pageinfo']['pagecount']) > 1) {
					$_return .= '<a href="javascript:void(0);" class="icon nr_next" onclick="sidebar_newreport(' . $uid . ',2)"></a>';
				}
				$_return .= '</div>';
			}else{
				$_return = '';
			}
            $kvcobj->set('return_' . $uid, $_return);
        }
        echo $_return;
    }

    //個人頁面報告 ajax
    function action_b16_1() {
        $uid = intval($this->get_q('uid', '0', 'int'));
        $page = intval($this->get_q('page', '1', 'int'));
		$kvcobj = getCache('block_b16', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return_' . $uid.'_'.$page);
        if (!$_return) {
		
			$data = $this->ProductReports->getReportsList(0, $uid, 0, "TB1.addtime desc", $page, 5, 1);
			$_return = '<ul class="newreport_list">';
			foreach ($data['result'] as $k => $v) {
				$data1 = $this->Product->getProductById($v['oid']);
				$_return .= '<li><i class="square"></i>
							<a href="' . optimize_url('product', 'reportDetail', '&pid=' . $v['oid'] . '&mtype=' . $data1['member_type'] . '&rid=' . $v['id']) . '">' . wordscut($v['title'], 20) . '</a></li>';
			}
			$_return .= '</ul>';
			if ($page > 1) {
				$_return .= '<a href="javascript:void(0);" class="icon nr_prev" onclick="sidebar_newreport(' . $uid . ',' . ($page - 1) . ')"></a>';
			}
			if (intval($data['pageinfo']['pagecount']) > $page) {
				$_return .= '<a href="javascript:void(0);" class="icon nr_next" onclick="sidebar_newreport(' . $uid . ',' . ($page + 1) . ')"></a>';
			}
		    $kvcobj->set('return_' . $uid.'_'.$page, $_return);
        }

        echo json_encode(array('report' => $_return));
    }

    //星級會員最新報告
    function action_b17() {
        $kvcobj = getCache('block_b17', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $data = $this->ProductReports->getReportsList(0, 0, 0, "TB1.addtime desc", 1, 2, 1, '', 0, 0, 2, 0);
            $_return = '<div class="hd"><img src="/images/title/title_03.jpg" alt=""/>
			</div><div class="bd"><ul class="doing_list">';
            foreach ($data['result'] as $k => $v) {
                if (!empty($v['content_json'])) {
                    $content_arr = json_decode($v['content_json'], true);
                    $ii = 1;
                    $pic_arr = array();
                    foreach ($content_arr as $v1) {
                        if (!empty($v1['p'])) {
                            $pic_arr[$ii] = PhotoResize($v1['p'], 116, 73,0);
                            $ii++;
                        }
                    }
                }
                $_return .= '<li>
                                <div class="avatar">
                                    <a href="' . optimize_url('person', 'report', 'username=' . $v['username']) . '" >
                                        <img src="' . imore_avatar($v['photo']) . '" width="56" alt="" />
                                    </a>
                                </div>
                                <div class="details_box">
                                        <p class="details">
                                            <span class="name"><a class="name" href="' . optimize_url('person', 'report', 'username=' . $v['username']) . '" >' . $v['username'] . '</a></span><span class="time">' . time_to_str($v['addtime']) . '</span>提交了'.($v['member_type']==5?"體驗":"試用").'報告：
                                        </p>
                                        <p class="desp">
                                            <a class="desp" href="' . optimize_url('product', 'reportDetail', 'mtype=' . $v['member_type'] . '&pid=' . $v['oid'] . '&rid=' . $v['id']) . '" >' . $v['title'] . '</a>
                                        </p>
                                </div>
								<div class="img_box"><a href="' . optimize_url('product', 'reportDetail', 'mtype=' . $v['member_type'] . '&pid=' . $v['oid'] . '&rid=' . $v['id']) . '"><img src="' . $pic_arr[1] . '" alt=""/>
                                            <img src="' . $pic_arr[2] . '" alt="" style="margin-left:5px;"/></a></div>
                        </li>';
            }
            $_return .= '</ul></div>';
            $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

    //index search
    function action_b18() {
		 $kvcobj = getCache('block_b18', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
			$_hot_arr = $ptype_arr = array();
			$product_layout_category_list = $this->Lookup->getLookup('product_layout_category', 0, 1, 9, 0);
			if (!empty($product_layout_category_list['result'])) {
				foreach ($product_layout_category_list['result'] as $k => $v) {
					$ptype_arr[$k]['id'] = $v['id'];
					$ptype_arr[$k]['name'] = $v['cname'];
					$ptype_li_list = $this->Lookup->getLookup('product_layout_category', 0, 1, 99, $v['id']);
					if (!empty($ptype_li_list['result'])) {
						foreach ($ptype_li_list['result'] as $k1 => $v1) {
							$ptype_arr[$k]['list'][$k1]['id'] = $v1['id'];
							$ptype_arr[$k]['list'][$k1]['name'] = $v1['cname'];
						}
					}
				}
			}
			$search_hot_arr = db_query_hash('sb_search_hotpicks', array('field' => 'cname', 'where' => 'live=1 and status=1', 'limit' => '3', 'order' => 'sequence asc'));
			if (!empty($search_hot_arr['result'])) {
				foreach ($search_hot_arr['result'] as $key => $value) {
					if (!empty($value['cname']))
						$_hot_arr[] = $value['cname'];
				}
			}

			$_return = '<div class="hd"><h2 class="title">搜尋</h2></div><div class="bd">';
			$_return .= '<form action="" method="post" id="index_search_form" name="index_search_form">';
			$_return .= '<input type="text" id="find" class="ipt_keyword" onkeyup="lookup(this.value,1);" name="find"  class="search_ipt" value="keyword" id="search" onfocus="find_onfocus(this);" onblur="find_onblur(this);"/><div id="autoSuggestionsList" style="width:154px;margin-top:-9px;border:1px solid #CCCCCC;"></div>';
			$_return .= '<select name="ptype" class="sel_1">';
			$_return .= '<optgroup label="全部分類"><option value ="0">全部分類</option></optgroup>';
			foreach ($ptype_arr as $k => $v) {
				$_return .= '<optgroup label="' . $v['name'] . '">';
				foreach ($v['list'] as $k1 => $v1) {
					$_return .= '<option value ="' . $v1['id'] . '">' . $v1['name'] . '</option>';
				}
				$_return .= '</optgroup>';
			}
			$_return .= "</select>";

			$brand = $this->Lookup->getLookup('brand');
			$_return .= '<select name="brand" class="sel_2"><option value ="0">全部品牌</option>';
			foreach ($brand['result'] as $k => $v) {
				$_return .= '<option value ="' . $v['id'] . '">' . $v['name'] . '</option>';
			}
			$_return .= "</select>";
			$_return .= "</form>";
			$_return .= '<a class="btn_search" href="javascript:void(0);" onclick="$(\'#index_search_form\').attr(\'action\',\'/search-product/\'+$(\'#find\').val()).submit()">
						<strong>搜尋</strong></a>';
			$_return .= '<dl><dt>熱門搜尋：</dt><dd>';
			foreach ($_hot_arr as $k => $v) {
				$_return .= "<a href='/search-product/" . $v . "'>" . $v . "</a> ";
			}
			$_return .= "</dd></dl></div>";
		    $kvcobj->set('return', $_return);
        }
        echo $_return;
    }

	 //f&b
    function action_b19() {
        $kvcobj = getCache('block_b19', array('expire' => KVC_EXPIRE));
        $_return = $kvcobj->get('return');
        if (!$_return) {
            $jsons = file_get_contents("http://gztest3.fnb.com.hk/default/api");
			$_data = json_decode($jsons,1);
			if(!empty($_data)){
				$_return = '<div class="hd">
							<h2 class="hd_title">Fashion & Beauty 流行新姿</h2>
						</div>
						<div class="bd">
							<div class="mag_box">
								<div class="img_box">
									<p class="img_p">
									<a href="'.$_data['data']['cover']['url'].'"> <span>
									<img src="'.$_data['data']['cover']['image'].'" alt="" width="155" height="193"/>
									</span></a></p>
								</div>
								<h4 class="title">'.$_data['data']['cover']['subject'].'</h4>
								<p class="desp">'.wordscut($_data['data']['cover']['message'],30).'</p>
							</div>
							<div class="gift_box">
								<div class="img_box">
									<p class="img_p">
												<a href="'.$_data['data']['gift']['url'].'"> <span>
									<img src="'.$_data['data']['gift']['image'].'" alt="" width="90" height="90"/>
									</span></a></p>
								</div>
								<i class="fnb_icon"></i>
								<h4 class="title">'.$_data['data']['gift']['subjectside'].'</h4>
								<p class="desp">'.wordscut($_data['data']['gift']['message'],30).'</p>
							</div>
						</div>';
			}
        }
        echo $_return;
    }
}

$webapp = new Block();
$webapp->run();
?>